package com.bigknow.appstore.proxy.handler.filter;

import com.bigknow.appstore.proxy.cache.ICacheManager;
import com.bigknow.appstore.proxy.exceptions.processor.impl.ErrorAssert;
import com.bigknow.appstore.proxy.handler.base.BaseInboundHandler;
import com.bigknow.appstore.proxy.log.ILogWriter;
import com.bigknow.appstore.proxy.server.IProxyServer;
import com.bigknow.appstore.proxy.util.HandlerVariables;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpMessage;

/**
 * 如果前面的handler都没有构建出requestVo那么此filter将进行拦截
 * Created by chaos on 2016/9/19.
 */
@ChannelHandler.Sharable
public class RequestVoFilterHandler extends BaseInboundHandler{

    public RequestVoFilterHandler(IProxyServer proxyServer, ICacheManager cacheManager, ILogWriter writer) {
        super(proxyServer, cacheManager, writer);
    }

    @Override
    public void read(ChannelHandlerContext ctx, FullHttpMessage msg) throws Exception {
        //2016-9-26 chaos 改造为throwError方式
/*        if(HandlerVariables.currentRequestVoLocal.get()==null){
            closeConnection(ctx.channel());
        }else{
            ctx.fireChannelRead(msg);
        }*/
        ErrorAssert.assertUriHasRequestVo(ctx,HandlerVariables.currentRequestVoLocal.get());
        ctx.fireChannelRead(msg);
    }
}
